package models

import "time"

type Shop struct {
	Id     int       `json:"id"`
	Name   string    `json:"name"`
	Price  float64   `json:"price"`
	Times  time.Time `json:"times"`
	Cate   string    `json:"cate"`
	Source string    `json:"source"`
}

func MysqlList(page int, pageSize int, name string) ([]Shop, int64, error) {
	var shop []Shop
	var total int64
	var query = DB.Model(&shop)
	if name != "" {
		query = query.Where("name like ? ", "%"+name+"%")
	}
	if err = DB.Order(&total).Error; err != nil {
		return nil, 0, err
	}
	if err = DB.Order("price desc").Offset((page - 1) * pageSize).Limit(pageSize).Find(&shop).Error; err != nil {
		return nil, 0, err
	}
	return shop, total, nil
}
